/* vue.groovy
    ##################################################
    # Created by zy                        #
    # Plugin install:  build user vars, vue                                                #
    # A Part of the Project jenkins-library          #
    ##################################################
*/
package org.devops

def nbuild(npmcmd, change_profile_dir, git_profile_path, nodebuildtag) {
    sh """
        if [ $change_profile_dir == 0  ]; then cd $git_profile_path; fi
        pwd
        rm -rf dist/*
        npm -v
        cnpm -v
        node -v
        npm config set https://mirrors.tuna.tsinghua.edu.cn/npm/ 
        $npmcmd install
        $npmcmd run build$nodebuildtag
        if [ ! -d "dist" ]; then
            echo "Error: dist directory不存在, 构建可能未成功. Exiting..."
            exit 1
        else
            mkdir tmp && mv dist/* tmp/ && rm -rf dist && mv tmp dist
            tar cjf dist.tar.gz dist           
        fi
    """
}

